<template>
  <div class="survey-box">
    <el-row type="flex" justify="space-between" align="middle" class="survey-hedaer">
      <div class="title">付费用户</div>
      <change-time :school="hasSchool" @update:time="changeTime" @update:school="changeSchool" />
    </el-row>
    <el-row class="ve-line-box"><ve-line :loading="loading" :data="chartData" :settings="chartSettings" :colors="colors" :extend="extendsConfig" /></el-row>
  </div>
</template>

<script>
import VeLine from 'v-charts/lib/line.common';
import ChangeTime from '../../../components/changetime.vue';
import 'v-charts/lib/style.css';
export default {
  components: {
    VeLine,
    ChangeTime
  },
  data() {
    return {
      time: 'today',
      mhm_id: 0,
      loading: false,
      hasSchool: false,
      chartData: {
        columns: ['date', 'payment_user_old', 'payment_user_new'],
        rows: []
      },
      chartSettings: {
        labelMap: {
          date: '日期',
          payment_user_old: '老付费用户',
          payment_user_new: '新付费用户'
        },
        yAxisName: ['新老用户付费趋势']
      },

      colors: ['#FF9595', '#6CA2FF'],
      extendsConfig: {
        grid: {
          right: 20,
          left: 20
        },
        xAxis(v) {
          v.forEach(i => {
            i.boundaryGap = false;
            i.axisLabel = {
              showMaxLabel: true,
              rotate: 65
            };
          });

          return v;
        },
        yAxis(v) {
          v.forEach(i => {
            i.minInterval = 1;
          });

          return v;
        }
      }
    };
  },
  created() {
    this.loadData();
  },
  methods: {
    changeTime: function(time) {
      this.time = time;
      this.loading = true;
      this.loadData();
    },
    changeSchool: function(mhm) {
      this.mhm_id = mhm;
      this.loading = true;
      this.loadData();
    },
    loadData: function() {
      this.$http.get(
        '/admin/data/student/payment/user',
        {
          time: this.time,
          mhm_id: this.mhm_id
        },
        response => {
          this.response = response.data;
          this.chartData.rows = this.response.rows;
          this.hasSchool = !!this.response.is_platform;
          this.loading = false;
        },
        errror => {
          this.loading = false;
        },
        false
      );
    }
  }
};
</script>

<style lang="scss" scoped>
.survey-box {
  background-color: #fff;
  min-height: 150px;
  margin-bottom: 20px;
  padding: 10px 20px 25px;
  .survey-hedaer {
    margin-bottom: 28px;
    height: 36px;
    padding-right: 20px;
    background-color: #f1f8ff;
    .title {
      color: #303133;
      font-size: 15px;
      padding-left: 6px;
      border-left: 2px solid #5191ff;
    }
  }

  .ve-line-box {
    margin-top: 24px;
    border: 1px solid #e4e7ed;
    padding: 20px 20px 0 20px;
  }
}
</style>
